package com.wyvoid.forum.web.action.controlPanel;

import com.wyvoid.core.persistent.Pagination;
import com.wyvoid.core.persistent.hibernate.HibernatePage;
import com.wyvoid.forum.annotations.Secure;
import com.wyvoid.forum.annotations.LoginUser;
import com.wyvoid.forum.domain.Message;
import com.wyvoid.forum.domain.User;
import com.wyvoid.forum.domain.UserProfile;
import com.wyvoid.forum.service.IFriendService;
import com.wyvoid.forum.service.IMessageService;
import com.wyvoid.forum.service.IUserService;
import com.wyvoid.forum.web.action.BaseAction;
import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.integration.spring.SpringBean;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidateNestedProperties;

/**
 * User: new
 * Date: 2007-6-6
 * Time: 10:13:40
 */

@UrlBinding("/controlPanel/controlPanel.do")
@LoginUser
public class ControPanelAction extends BaseAction {
    @SpringBean
    private IMessageService messageService;
    @SpringBean
    private IFriendService friendService;
    @SpringBean
    private IUserService userService;
    private User user;
    private Message message;

    private HibernatePage myMessageList;
    private HibernatePage friendList;
    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
    }

    public void setFriendService(IFriendService friendService) {
        this.friendService = friendService;
    }


    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setMessageService(IMessageService messageService) {
        this.messageService = messageService;
    }


    public HibernatePage getMyMessageList() {
        return myMessageList;
    }


    public HibernatePage getFriendList() {
        return friendList;
    }


    @DefaultHandler
    @DontValidate
    public Resolution myControlPanel() {
        Pagination pagination = new Pagination();
        pagination.setPageNumber(1);
        pagination.setPageSize(10);
        user=userService.getUser(getContext().getUserId());
        myMessageList = messageService.getMyMessages(getContext().getUserId(), pagination);
        return getBBSResolution("controlPanel/myControlPanel");
    }

    @DontValidate
    public Resolution getFriends() {
        Pagination pagination = new Pagination();
        pagination.setPageNumber(1);
        pagination.setPageSize(10);
        friendList = friendService.getFriendsByUserId(getContext().getUserId(), pagination);
        return getBBSResolution("controlPanel/friends");
    }
}
